import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button, Form, DatePicker, Card, Table } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import dataEditCreate from '../../addons/DataEdit'
import * as datetime from '../../../utils/datetime'
import * as compDiviService from '../../../services/AccountDivi';
const ButtonGroup = Button.Group;
class BaseClfhForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dateValue: null,
      loading:false
    }
  }
  showDiviHandler() {
    let dateString = this.state.dateValue;
    let ods = this.props.odsDate
    if (dateString && dateString > ods) {
      message.error("追溯日期不能大于系统当前日期")
      return
    } else {
      this.setState({loading:true})  
      compDiviService.UpdateDiviPro({ dateString}
      ).then(function (data) {
        if (data === 'OK') {
          message.success('数据处理成功！')
          this.setState({loading:false})  
        } else {
          message.error('数据处理失败！' + data)
          return;
        }
      }.bind(this)).catch(function (ex) {
        console.log('请求出错', ex)
      });
    }
  }
  SelDate(date, dateString) {
    this.state.dateValue = dateString;
  }
  findrq() {
    compDiviService.defaultDate({}
    ).then(function (data) {
      message.info("追溯日期为：" + data + ".")
    }.bind(this)).catch(function (ex) {
      console.log('请求出错', ex)
    });
  }
  render() {
    let { showEdit, record, offsetWidth, offsetHeight, permID, popedomTypes } = this.props
    let x = (offsetWidth / 2 - 10) / 2
    let y = offsetHeight - 115
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <div className={styles.create}>
          <ButtonGroup style={{ zIndex: 0 }}>
            <Button onClick={this.findrq.bind(this)}>默认追溯日期</Button>
          </ButtonGroup>
        </div>
        <Card style={{ height: y }} bodyStyle={{ padding: 0 }}>
          <div style={{ marginLeft: x, align: 'center', color: 'red' }}>
            <br /><br /><br /><br />
            注意：<br/>
            1、此功能在帐户关系修改和考核参数修改,利润费用参数变化时执行;<br />
            2、如果考核参数修改影响到以前月份的考核结果, 需要调用此功能;<br />
            3、计算利润、费用的相关参数发生变化时,需要调用此功能进行调整;<br />
            4、若不选择追溯日期，默认追溯730天，若选择则从选择的日期开始处理; <br />
            5、追溯时间越长，系统处理时间越长，在执行期间不要进行帐户关系修改和参数修改操作。<br />
            <br />
            <div style={{ align: 'center' }}>
              <span style={{ color: 'black', height: 50 }}>
                追溯日期:
              </span>
              <span>
                <DatePicker onChange={this.SelDate.bind(this)} style={{ 'vertical-align': 'bottom' }} />
              </span>
              <span style={{ marginLeft: 40 }}><Button loading={this.state.loading} onClick={this.showDiviHandler.bind(this)} type="primary">处理分户修改</Button>
              </span>
            </div>
          </div>
        </Card>
      </div>
    )
  }
}

function mapStateToProps(state) {
  const { offsetHeight, userID, orgID, pOrgID, popedomTypes, offsetWidth, odsDate } = state.menus
  return {
    userID,
    orgID,
    pOrgID,
    popedomTypes,
    offsetHeight,
    offsetWidth,
    odsDate
  }
}
BaseClfhForm = connect(mapStateToProps)(BaseClfhForm)
export default BaseClfhForm;

let render = (props) => React.createElement(BaseClfhForm, props);
let f = new Factory()
f.set("BaseClfhForm", render)
